package com.badibadi.activity;

import com.badibadi.fragment.AfterLandingAddFriendsMsgItemFragment0;
import com.badibadi.fragment.AfterLandingAddFriendsMsgItemFragment1;
import com.badibadi.fragment.AfterLandingAddFriendsMsgItemFragment2;
import com.badibadi.fragment.AfterLandingMyHomePageFriendsApplyForFragment;
import com.badibadi.mytools.DisplayUtil;
import com.badibadi.mytools.ImageTools;
import com.badibadi.uniclubber.R;
import com.badibadi.uniclubber.R.layout;
import com.badibadi.uniclubber.R.menu;
import com.libjph.util.StringUtil;
import com.view.my_view.PaoPao_Button;

import android.os.Bundle;
import android.app.ActionBar;
import android.app.ActionBar.Tab;
import android.app.Activity;
import android.app.FragmentTransaction;
import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.drawable.Drawable;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;

//after_landing_title1
public class InvitationsActivity extends BaseActivity {

	private ActionBar actionBar;

	private String messageNum;
	NotificationManager nm;
	static final int NOTIFICATION_ID = 0x123;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		// goToTheTitle();
		setContentView(R.layout.activity_invitations);
		messageNum = getIntent().getStringExtra("messageNum");
		nm = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
		initActionBar();

	}

	private void initActionBar() {
		// TODO Auto-generated method stub
		actionBar = getActionBar();

		// 设置ActionBar的背景
		actionBar.setBackgroundDrawable(getResources().getDrawable(
				R.drawable.blue_bg));
		// 设置导航模式(只有一个呗选中)
		actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
		// actionBar.setDisplayShowTitleEnabled(false);
		actionBar.setDisplayShowTitleEnabled(true);// 设置是否显示标签
		actionBar.setDisplayHomeAsUpEnabled(true);
		actionBar.setStackedBackgroundDrawable(getResources().getDrawable(
				R.drawable.white_bg));
		actionBar.setTitle(getResources().getString(R.string.l_xb78));
		// actionBar.setDisplayUseLogoEnabled(true);
		// actionBar.setHomeButtonEnabled(true);//将应用程序的标题设为可点击
		actionBar.setDisplayHomeAsUpEnabled(true);// 将应用程序标题设为可点击，并且加上左键头
		// actionBar.setSelectedNavigationItem(0);//下拉列表导航
		LayoutInflater inflater = LayoutInflater.from(InvitationsActivity.this);
		View v = inflater.inflate(R.layout.notice_title, null);
		LinearLayout paopao = (LinearLayout) v.findViewById(R.id.paoPaoButton1);
		TextView message = (TextView) v.findViewById(R.id.messageNum);
		// paopao.setBackgroundResource(R.drawable.after_landing_title2);
		if (!StringUtil.isNullOrEmpty(messageNum)) {
//			Intent intent = new Intent(InvitationsActivity.this,
//					ClubListActivity.class);
//			PendingIntent pi = PendingIntent.getActivity(InvitationsActivity.this,
//					0, intent, 0);
//			Notification notify = new Notification.Builder(this)
//			// 设置打开该通知，该通知自动消失
//					.setAutoCancel(true)
//					// 设置显示在状态栏的通知提示信息
//					.setTicker("有新消息")
//					// 设置通知的图标
//					.setSmallIcon(R.drawable.ic_launcher)
//					// 设置通知内容的标题
//					.setContentTitle("一条新通知")
//					// 设置通知内容
//					.setContentText("恭喜你，您加薪了，工资增加20%!")
//					// Notification.DEFAULT_SOUND设置默认声音。
//					// Notification.DEFAULT_VIBRATE设置默认振动。
//					// Notification.DEFAULT_LIGHTS设置默认闪光灯
//					// Notification.DEFAULT_ALL设置使用系统默认的声音、默认LED灯，振动。
//					 .setDefaults(Notification.DEFAULT_SOUND
//					 |Notification.DEFAULT_LIGHTS)
//					// 设置通知的自定义声音					
//					// 设置自定义振动
//					// .setVibrate(new long[] { 0, 50, 100, 150 })
//					.setWhen(System.currentTimeMillis())
//					// 设改通知将要启动程序的Intent
//					.setContentIntent(pi).build();
//			// 发送通知
//			nm.notify(NOTIFICATION_ID, notify);
			if (Integer.parseInt(messageNum) > 99) {
				message.setText("99+");
			} else {
				message.setText(messageNum);
			}
		}
		if (messageNum.equals("0")) {
			v.findViewById(R.id.f_messageNum).setVisibility(View.INVISIBLE);
		}
		Bitmap d = ImageTools.loadBitmapFromView(this, v,
				DisplayUtil.dip2px(this, 70), DisplayUtil.dip2px(this, 70));
		// Bitmap d = ImageTools.loadBitmapFromView(this, v, 150, 150);
		Drawable dd = ImageTools.bitmapToDrawable(d);
//		   

		actionBar.setIcon(dd);// 设置应用标题的背景图
		// 第一个选项卡
		ActionBar.Tab tab = actionBar.newTab();
		ActionBar.Tab tab2 = actionBar.newTab();
		ActionBar.Tab tab3 = actionBar.newTab();
		actionBar.addTab(actionBar.newTab()
				.setText(getResources().getString(R.string.Friends_validation))
				// .setIcon(getResources().getDrawable(R.drawable.ic_launcher))
				.setTag(0).setTabListener(new MyTabListener()));
		actionBar.addTab(actionBar.newTab()
				.setText(getResources().getString(R.string.ClubInvitation))
				.setTag(1)
				// .setIcon(getResources().getDrawable(R.drawable.ic_launcher))
				.setTabListener(new MyTabListener()));
		actionBar.addTab(tab3
				.setText("@" + getResources().getString(R.string.Me)).setTag(2)
				// .setIcon(getResources().getDrawable(R.drawable.ic_launcher))
				.setTabListener(new MyTabListener()));
	}

	@Override
	public boolean onOptionsItemSelected(MenuItem item) {
		// TODO Auto-generated method stub
		switch (item.getItemId()) {
		case android.R.id.home:
			Intent intent = new Intent(this, AfterLandingActivity.class);
			intent.putExtra("isStartTwoClose", true);
			startActivity(intent);
			finish();
			overridePendingTransition(R.anim.slide_left2, R.anim.slide_right2);
			break;
		}
		return true;
	}

	public class MyTabListener implements ActionBar.TabListener {

		@Override
		public void onTabReselected(Tab tab, FragmentTransaction ft) {
			// TODO Auto-generated method stub
		}

		@Override
		public void onTabSelected(Tab tab, FragmentTransaction ft) {
			// TODO Auto-generated method stub
			switch (Integer.parseInt(tab.getTag().toString())) {
			case 0:
				ft.replace(R.id.invitations_layout,
						new AfterLandingAddFriendsMsgItemFragment0(),
						"AfterLandingAddFriendsMsgItemFragment0()");
				break;
			case 1:
				ft.replace(R.id.invitations_layout,
						new AfterLandingAddFriendsMsgItemFragment1(),
						"AfterLandingAddFriendsMsgItemFragment1()");
				break;
			case 2:
				ft.replace(R.id.invitations_layout,
						new AfterLandingAddFriendsMsgItemFragment2(),
						"AfterLandingAddFriendsMsgItemFragment2()");
				break;
			}
		}

		@Override
		public void onTabUnselected(Tab tab, FragmentTransaction ft) {
			// TODO Auto-generated method stub
		}

	}
}
